package com.rabbit.adapter;

import java.util.List;

import com.rabbit.R;
import com.rabbit.model.Shop;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * ShopListAdapter
 * 
 * @author zhilei.liu 2014-12-12下午5:31:46
 */
public class ShopListAdapter extends BaseAdapter {

    private Context mContext;

    private List<Shop> mShops;

    public ShopListAdapter(Context context, List<Shop> shops) {
        mContext = context;
        mShops = shops;
    }

    @Override
    public int getCount() {

        return mShops == null ? 0 : mShops.size();
    }

    @Override
    public Object getItem(int position) {
        return mShops == null ? null : mShops.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.shop_list_item, null);
            holder = new ViewHolder();
            convertView.setTag(holder);
            holder.evalutionNum = (TextView) convertView
                    .findViewById(R.id.tv_item_shop_evaluation_num);
            holder.header = (ImageView) convertView
                    .findViewById(R.id.iv_item_shop_head);
            holder.name = (TextView) convertView
                    .findViewById(R.id.tv_item_shop_name);
            holder.publicPraiseNum = (TextView) convertView
                    .findViewById(R.id.tv_item_shop_public_praise_num);
            holder.salesNum = (TextView) convertView
                    .findViewById(R.id.tv_item_shop_sales_volume_num);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        
        Shop shop = (Shop) getItem(position);
        
        holder.salesNum.setText(""+shop.getSalesValume());
        holder.evalutionNum.setText(""+shop.getEvalution());
        holder.name.setText(shop.getName());
        holder.publicPraiseNum.setText(""+shop.getPublicPraise());
        
        return convertView;
    }

    public class ViewHolder {

        ImageView header;
        TextView name;
        TextView salesNum;
        TextView evalutionNum;
        TextView publicPraiseNum;

    }

}
